package com.yztc.ui.cook;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yztc.bean.cook.NewFoodTypeBean;
import com.yztc.chunboapp.R;
import com.yztc.utils.ImageHelper;

import java.util.List;

/**
 * Created by Administrator on 2016/10/8.
 */
public class NewFoodAdapter extends BaseAdapter{
    private Context mContext;
    private List<NewFoodTypeBean> list;
    private LayoutInflater inflater;

    public NewFoodAdapter(Context mContext, List<NewFoodTypeBean> list){
        this.mContext=mContext;
        this.list=list;
        inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder=null;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.fragment_cook_listview_item,parent,false);
            myViewHolder=new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }
        myViewHolder.tv_name_listview.setText(list.get(position).getChefName());
        myViewHolder.tv_title_listview.setText(list.get(position).getDisplayName());
        myViewHolder.tv_info_listview.setText(list.get(position).getDesc());
        ImageHelper.getRoundImage(mContext,list.get(position).getChefImg(),myViewHolder.img_name_listview);
        ImageHelper.getNormalImage(mContext,list.get(position).getPicUrl(),myViewHolder.img_food_listview);
        return convertView;
    }
    class MyViewHolder{
        private ImageView img_food_listview;
        private TextView tv_name_listview;
        private TextView tv_title_listview;
        private TextView tv_info_listview;
        private ImageView img_name_listview;
        public MyViewHolder(View convertView){
            img_food_listview=
                    (ImageView) convertView.findViewById(R.id.img_food_listview);
            img_name_listview=
                    (ImageView) convertView.findViewById(R.id.img_name_listview);
            tv_name_listview=
                    (TextView) convertView.findViewById(R.id.tv_name_listview);
            tv_title_listview=
                    (TextView) convertView.findViewById(R.id.tv_title_listview);
            tv_info_listview=
                    (TextView) convertView.findViewById(R.id.tv_info_listview);
        }
    }
}
